<template>
  <!-- 供方预付款-新增 -->
  <div class="e-form">
    <div class="tabs">
      <div class="tabs-title">基本信息</div>
      <div style="width: 100%" class="form">
        <el-form :model="formData" label-width="150px">
          <el-row>
            <el-col :span="12">
              <el-form-item label="结算编号:">
                <el-input  v-model="formData.billNo"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="单据机构:">
                <el-input
                  disabled
                  placeholder="请填写"
                  v-model="formData.orgName"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="合同类型:">
                <el-input
                  placeholder="请填写"
                  v-model="formData.contractType"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="合同名称:">
                <el-input
                  placeholder="请填写"
                  v-model="formData.contractName"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="结算单位:">
                <el-input
                  placeholder="请填写"
                  v-model="formData.settlementUnitName"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="加扣款日期:">
                <el-date-picker
                  v-model="formData.settlementDate"
                  type="date"
                  placeholder="选择日期"
                  :clearable="false"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="加扣款金额(元):">
                <el-input
                  placeholder="请填写"
                  v-model="formData.plusDeductionAmount"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="返还保证金金额(元)">
                <el-input
                  placeholder="请填写"
                  v-model="formData.returnDepositAmount"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="币种">
                <el-input
                  placeholder="请填写"
                  v-model="formData.currency"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="传财务共享">
                <el-input
                  placeholder="请填写"
                  v-model="formData.showEas"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="本位币:">
                <el-input
                  placeholder="请填写"
                  v-model="formData.baseCurName"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="状态">
                {{ formData.state }}
                <!-- 草稿/审核中/共享审核中/已审核/已关闭/已作废 -->
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="加扣款金额(本位币):">
                <el-input
                  placeholder="请填写"
                  v-model="formData.baseCurPlusDeductionAmount"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="返还保证金金额:">
                <el-input
                  placeholder="请填写"
                  v-model="formData.baseCurReturnDepositAmount"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-form-item label="备注">
              <el-input
                type="textarea"
                :rows="2"
                placeholder="请输入内容"
                v-model="formData.remarks"
              >
              </el-input>
            </el-form-item>
          </el-row>
        </el-form>
      </div>
    </div>
    <div class="buttons">
      <el-button type="primary" style="background: #2e61d7" @click="save()"
        >保存</el-button
      >
      <el-button type="primary" style="background: #2e61d7" @click="submit()"
        >保存并提交</el-button
      >

      <el-button @click="cancel()">关闭</el-button>
    </div>
    <span style="display: none">{{ localPopConfirm }}</span>
  </div>
</template>

<script>
import '@/utils/jquery.scrollTo.min'
import { mapMutations, mapState } from 'vuex'
import { showSuccessPop } from '@/utils/common'

export default {
    data () {
        return {
            //表单数据
            formData: {
                billNo: '', //结算编号
                orgName: '', //单据机构
                contractType: '', //合同类型
                contractName: '', //合同名称
                settlementUnitName: '', //结算单位
                settlementDate: '', //加扣款日期
                plusDeductionAmount: '', //加扣款金额（元）
                returnDepositAmount: '', //返还保证金
                currency: '', //币种
                showEas: '', //传财务共享
                baseCurName: '', //本位币
                state: '草稿', //状态
                baseCurPlusDeductionAmount: '', // /加扣款金额(本位币)
                baseCurReturnDepositAmount: '', //返还保证金额
                remarks: '', //备注
            },
            orgId: '', //机构id
            orgName: '', //机构名称
            isSkip: false, //是否跳转
        }
    },
    computed: {
        ...mapState({
            options: state => state.contract.ctClassify,
            popConfirm: 'popConfirm',
            popStatus: 'popStatus',
        }),
        localPopConfirm () {
            if (this.popConfirm) {
                switch (this.popStatus) {
                case 'prompt':
                    this.delData()
                    break
                case 'success':
                    if (this.isSkip) this.handleClose()
                    break
                }
                this.setPopConfirm(false)
            }
            return this.popConfirm
        },
    },
    components: {},
    created () {
        let data = JSON.parse(localStorage.getItem('vuex'))
        this.orgId = data.userInfo.orgInfo.orgId
        this.orgName = data.userInfo.orgInfo.orgName
        this.formData.orgName = data.userInfo.orgInfo.orgName
    },
    mounted () {},
    beforeDestroy () {},
    methods: {
        ...mapMutations(['setPopConfirm']),

        //提交
        submit () {
            let settlementDate = this.getTime(this.formData.settlementDate)
            this.$Ajax
                .httpPost({
                    url: '/materialsettle/supplierPlusDeductionSettlement/create',
                    params: {
                        baseCurId: '', //	本位币id
                        baseCurName: this.formData.baseCurName, //本位币名称
                        baseCurPlusDeductionAmount: parseInt(this.formData.baseCurPlusDeductionAmount), //	加扣款金额(本位币)
                        baseCurRate: 0, //本位币汇率
                        baseCurReturnDepositAmount: parseInt(this.formData.baseCurReturnDepositAmount), //	返还保证金金额(本位币)
                        billId: '', //	供方加扣款结算id
                        billNo: this.formData.billNo, //	结算编号
                        contractBillId: '', //	合同id
                        contractBillNo: '', //	合同编号
                        contractName: this.formData.contractName, //	合同名称
                        contractType: parseInt(this.formData.contractType), //合同类型
                        dtls: [], //供方加扣款结算-加扣款明细集合
                        easId: '', //	财务Id
                        founderId: '', //	创建人Id
                        founderName: '', //创建人名称
                        gmtCreate: '', //	创建时间
                        gmtModified: '', //	更新时间
                        nullifyCreated: '', //	作废时间
                        nullifyCreator: '', //	作废人
                        nullifyCreatorId: '', //	作废人id
                        nullifyDescription: '', //	作废描述
                        nullifyReason: '', //	作废原因
                        orgId: this.orgId, //	所属机构id
                        orgName: this.formData.orgName, //	所属机构名称
                        plusDeductionAmount: parseInt(this.formData.plusDeductionAmount), //加扣款金额(元)
                        remarks: this.formData.remarks, //备注信息
                        returnDepositAmount: parseInt(this.formData.returnDepositAmount), //	返还保证金金额(元)
                        returnDepositDtls: [], //供方加扣款结算-返还保证金明细集合
                        rmbId: '', //	人民币id
                        rmbName: '', //	人民币名称
                        rmbPlusDeductionAmount: 0, //	加扣款金额(人民币)
                        rmbRate: 0, //人民币汇率
                        rmbReturnDepositAmount: 0, //	返还保证金金额(人民币)
                        settlementDate: settlementDate, //	结算日期
                        settlementUnitId: '', //	结算单位id
                        settlementUnitName: this.formData.settlementUnitName, //	结算单位名称
                        state: '0', //单据状态
                        workId: '', //流程id
                    },
                })
                .then(() => {
                    showSuccessPop('保存成功！')
                    this.isSkip = false
                    this.$router.push('/supplierAddDeductionsClose')
                })
        },

        //保存按钮
        save () {
            let settlementDate = this.getTime(this.formData.settlementDate)
            this.$Ajax
                .httpPost({
                    url: '/materialsettle/supplierPlusDeductionSettlement/create',
                    params: {
                        baseCurId: '', //	本位币id
                        baseCurName: this.formData.baseCurName, //本位币名称
                        baseCurPlusDeductionAmount: parseInt(this.formData.baseCurPlusDeductionAmount), //	加扣款金额(本位币)
                        baseCurRate: 0, //本位币汇率
                        baseCurReturnDepositAmount: parseInt(this.formData.baseCurReturnDepositAmount), //	返还保证金金额(本位币)
                        billId: '', //	供方加扣款结算id
                        billNo: this.formData.billNo, //	结算编号
                        contractBillId: '', //	合同id
                        contractBillNo: '', //	合同编号
                        contractName: this.formData.contractName, //	合同名称
                        contractType: parseInt(this.formData.contractType), //合同类型
                        dtls: [], //供方加扣款结算-加扣款明细集合
                        easId: '', //	财务Id
                        founderId: '', //	创建人Id
                        founderName: '', //创建人名称
                        gmtCreate: '', //	创建时间
                        gmtModified: '', //	更新时间
                        nullifyCreated: '', //	作废时间
                        nullifyCreator: '', //	作废人
                        nullifyCreatorId: '', //	作废人id
                        nullifyDescription: '', //	作废描述
                        nullifyReason: '', //	作废原因
                        orgId: this.orgId, //	所属机构id
                        orgName: this.formData.orgName, //	所属机构名称
                        plusDeductionAmount: parseInt(this.formData.plusDeductionAmount), //加扣款金额(元)
                        remarks: this.formData.remarks, //备注信息
                        returnDepositAmount: parseInt(this.formData.returnDepositAmount), //	返还保证金金额(元)
                        returnDepositDtls: [], //供方加扣款结算-返还保证金明细集合
                        rmbId: '', //	人民币id
                        rmbName: '', //	人民币名称
                        rmbPlusDeductionAmount: 0, //	加扣款金额(人民币)
                        rmbRate: 0, //人民币汇率
                        rmbReturnDepositAmount: 0, //	返还保证金金额(人民币)
                        settlementDate: settlementDate, //	结算日期
                        settlementUnitId: '', //	结算单位id
                        settlementUnitName: this.formData.settlementUnitName, //	结算单位名称
                        state: '0', //单据状态
                        workId: '', //流程id
                    },
                })
                .then(() => {
                    showSuccessPop('保存成功！')
                    this.isSkip = false

                })
        },
        //取消按钮
        cancel () {
            this.$router.push('/supplierAddDeductionsClose')
        },
        //日期转换格式
        getTime (dt) {
            var year = dt.getFullYear() //年
            var month = dt.getMonth() + 1 //月
            var date = dt.getDate() //日
            month = month < 10 ? '0' + month : month
            date = date < 10 ? '0' + date : date
            var str = year + '-' + month + '-' + date
            return str
        },
    },
}
</script>

<style lang="scss" scoped>
.buttons {
  left: 0;
}
.e-form {
  margin-bottom: 80px;
  padding: 0 20px;
  .tabs-title::before {
    content: "";
    height: 22px;
    width: 8px;
    border-radius: 40px;
    background-color: #2e61d7;
    display: block;
    position: absolute;
    left: 20px;
    margin-right: 20px;
  }
}

.e-table {
  background: #fff;
}

.el-tab-pane {
  margin-left: -10px;
}
</style>
